package com.netease.evo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author rui.duan
 * @version 1.0
 * @className UserTypeEnum
 * @description 用户类型
 * @date 2021-11-1 11:39
 */
@Getter
@AllArgsConstructor
public enum UserTypeEnum {
    //待通知
    STUDENT(1, "学生"),
    TEACHER(2, "老师")
    ;

    private Integer code;
    private String value;


    /**
     * 根据code获取值
     *
     * @param code
     * @return
     */
    public static String getValueByCode(Integer code) {
        UserTypeEnum caseCheckTypeEnum = getByCode(code);
        return Optional.ofNullable(caseCheckTypeEnum).map(UserTypeEnum::getValue).orElse(null);
    }

    public static UserTypeEnum getByCode(Integer code) {
        UserTypeEnum[] values = UserTypeEnum.values();
        return Arrays.stream(values).filter(e -> e.code.equals(code)).findFirst().orElse(null);
    }

    /**
     * 根据value获取code
     *
     * @param value
     * @return
     */
    public static Integer getCodeByValue(String value) {
        UserTypeEnum[] values = UserTypeEnum.values();
        return Arrays.stream(values).filter(e -> e.value.equalsIgnoreCase(value)).map(UserTypeEnum::getCode).findFirst().orElse(null);
    }
}
